<?php

/* ******************************
 *	Request aJax actions
* ******************************
*/

require_once('../../includes/classes/core.php');
include('../../includes/classes/log.class.php');
$log 		= new log();
$action 	= $_REQUEST['act'];
$error		= '';
$data		= '';

//incomming
$incom_id				= $_REQUEST['id'];
$controler_id			= $_REQUEST['controler_id'];
$call_date				= $_REQUEST['call_date'];
$site_user_pin			= $_REQUEST['pin'];
$call_type_id			= $_REQUEST['call_type_id'];
$phone					= $_REQUEST['phone'];
$category_id			= $_REQUEST['category_id'];
$problem_date			= $_REQUEST['problem_date'];
$call_content			= $_REQUEST['call_content'];
$category_parent_id 	= $_REQUEST['category_parent_id'];
$call_status_id			= $_REQUEST['call_status_id'];

$pay_type_id			= $_REQUEST['pay_type_id'];
$bank_id				= $_REQUEST['bank_id'];
$card_type_id			= $_REQUEST['card_type_id'];
$pay_aparat_id			= $_REQUEST['pay_aparat_id'];
$object_id				= $_REQUEST['object_id'];
$source_id				= $_REQUEST['source_id'];


// site_user
$personal_pin			= $_REQUEST['personal_pin'];
$personal_id			= $_REQUEST['personal_id'];
$personal_phone			= $_REQUEST['personal_phone'];
$mail				    = $_REQUEST['mail'];
$name				    = $_REQUEST['name'];
$friend_pin				= $_REQUEST['friend_pin'];

//task
$persons_id			    = $_REQUEST['persons_id'];
$task_type_id			= $_REQUEST['task_type_id'];
$priority_id			= $_REQUEST['priority_id'];
$comment 	        	= $_REQUEST['comment'];
$task_department_id 	= $_REQUEST['task_department_id'];
$hidden_inc				= $_REQUEST['hidden_inc'];
$edit_id				= $_REQUEST['edit_id'];
$delete_id				= $_REQUEST['delete_id'];

// file
$rand_file				= $_REQUEST['rand_file'];
$file					= $_REQUEST['file_name'];

$start 	= 	$_REQUEST['start1'];
$end 	= 	$_REQUEST['end1'];

if($start != '' && $end != ''){
    $start = $db->convertDateTime($start);
    $end = $db->convertDateTime($end); 
}

switch ($action) {
	case 'get_add_page':
		$number		= $_REQUEST['number'];
		$page		= GetPage($res='', $number);
		$data		= array('page'	=> $page);

		break;
	case 'disable':
		$incom_id				= $_REQUEST['id'];
		mysql_query("			UPDATE `incomming_call`
									    SET `actived`=0
										WHERE `id`=$incom_id ");
		break;
	case 'get_edit_page':
		$page		= GetPage(Getincomming($incom_id));

		$data		= array('page'	=> $page);

		break;
	case 'get_list' :
		$count  =       $_REQUEST['count'];
                $hidden =       $_REQUEST['hidden'];
                
                
                $fillter_all    =       $_REQUEST['fillter_all'];
                mysql_query("SET @i = 0;");
                $rResult = mysql_query("SELECT          `all`.task_id,
                                                                                        `all`.original_id,
                                                                                        DATE_FORMAT(`all`.`date`,'%d/%m/%y <span style=\"font-weight: bold;\">%H:%i:%s</span>') AS dateee,
                                                                                        `all`.pin,
                                                                                        `all`.pid,
                                                                                        `all`.phone,
                                                                                        `all`.cat,
                																		`all`.`money`,
                                                                                        `all`.user1,
                                                                                        `all`.user2,
                                                                                        `all`.`status`,
                                                                                        `all`.duration,
                                                                                        `all`.file_name
                                                        FROM `all`
                                                        WHERE  !ISNULL(date) AND `all`.`date`  BETWEEN  '$start'  And  '$end' AND file_name LIKE '%$fillter_all%'
                                                        ORDER BY date DESC");
                  
                $data = array(
                                "aaData"        => array()
                );

                while ( $aRow = mysql_fetch_array( $rResult ) )
                {
                        $row = array();
                        $row1 = array();
                        
                for ( $i = 0 ; $i < $count ; $i++ )
                        {
                        
                                if ($i==0){
                                        if (substr($aRow[$i],2,1)=='a')
                                        {
                                                
                                                {       $row[] = '<div style="background: #ccdd66; WIDTH: 150%;">'.$aRow[$i].'</div>';}
                                        };
                                                
                        }
                                
                                if($i==10){
                                if      ($aRow[$i]=='გადაცემულია გასარკვევად')                  {       $row[] = '<div style="background: #FF5555; WIDTH: 150%;">'.$aRow[$i].'</div>';}
                                                 elseif ($aRow[$i]=='გარკვევის პროცესშია')      {       $row[] = '<div style="background:#FFFF55; WIDTH: 150%;">'.$aRow[$i].'</div>';}
                                                 elseif ($aRow[$i]=='მოგვარებულია, აცნობეთ')    {       $row[] = '<div style="background: #B1EF87; WIDTH: 150%;">'.$aRow[$i].'</div>';}
                                                 elseif ($aRow[$i]=='დასრულებული')      {       $row[] = '<div style="background: #33dd33; WIDTH: 150%;">'.$aRow[$i].'</div>';}
                                                 else   { $row[] = $aRow[$i];}  
                                
                                }else   { $row[] = $aRow[$i];}
                        }
                        $data['aaData'][] = $row;
                }
                
                break;
        case 'save_incomming':
                $incom_id = $_REQUEST['id'];
                $task_type_id = $_REQUEST['task_type_id'];
                if($incom_id == ''){
                        
        
                }else {
                        
                        Saveincomming($call_type_id, $phone, $category_id, $category_parent_id, $object_id, $pay_type_id, $bank_id, $card_type_id, $pay_aparat_id,  $problem_date, $call_content, $source_id, $file,$rand_file);
                        
                        Savetask($incom_id, $persons_id,  $task_type_id, $priority_id, $task_department_id, $comment);
                 }
                break;
	case 'save_incomming':
		$incom_id = $_REQUEST['id'];
		$task_type_id = $_REQUEST['task_type_id'];
		if($incom_id == ''){
			
	
		}else {
			
			Saveincomming($call_type_id, $phone, $category_id, $category_parent_id, $object_id, $pay_type_id, $bank_id, $card_type_id, $pay_aparat_id,  $problem_date, $call_content, $source_id, $file,$rand_file);
			
			Savetask($incom_id, $persons_id,  $task_type_id, $priority_id, $task_department_id, $comment);
		}
		break;
	case 'move_incomming':
	
		note_incomming();
	
		break;
	case 'get_calls':
	
		$data		= array('calls' => getCalls());
	
		break;
		
		case 'delete_file':
		
			mysql_query("DELETE FROM file WHERE id = $delete_id");
		
			$increm = mysql_query("	SELECT  `name`,
					`rand_name`,
					`id`
					FROM 	`file`
					WHERE   `incomming_call_id` = $edit_id
					");
		
			$data1 = '';
		
			while($increm_row = mysql_fetch_assoc($increm))	{
			$data1 .='<tr style="border-bottom: 1px solid #85b1de;">
				          <td style="width:110px; display:block;word-wrap:break-word;">'.$increm_row[name].'</td>
				          <td ><button type="button" value="media/uploads/file/'.$increm_row[rand_name].'" style="cursor:pointer; border:none; margin-top:25%; display:block; height:16px; width:16px; background:none;background-image:url(\'media/images/get.png\');" id="download" ></button><input type="text" style="display:none;" id="download_name" value="'.$increm_row[rand_name].'"> </td>
						          <td ><button type="button" value="'.$increm_row[id].'" style="cursor:pointer; border:none; margin-top:25%; display:block; height:16px; width:16px; background:none; background-image:url(\'media/images/x.png\');" id="delete"></button></td>
 					  </tr>';
		}
		
		$data = array('page' => $data1);
		
				break;
		
				case 'up_now':
				$user		= $_SESSION['USERID'];
				if($rand_file != ''){
				mysql_query("INSERT INTO 	`file`
				( 	`user_id`,
				`incomming_call_id`,
				`name`,
				`rand_name`
				)
				VALUES
				(	'$user',
				'$edit_id',
				'$file',
				'$rand_file'
				);");
				}
		
				$increm = mysql_query("	SELECT  `name`,
				`rand_name`,
				`id`
				FROM 	`file`
				WHERE   `incomming_call_id` = $edit_id
				");
		
				$data1 = '';
		
				while($increm_row = mysql_fetch_assoc($increm))	{
				$data1 .='<tr style="border-bottom: 1px solid #85b1de;">
				<td style="width:110px; display:block;word-wrap:break-word;">'.$increm_row[name].'</td>
				<td ><button type="button" value="media/uploads/file/'.$increm_row[rand_name].'" style="cursor:pointer; border:none; margin-top:25%; display:block; height:16px; width:16px; background:none;background-image:url(\'media/images/get.png\');" id="download" ></button><input type="text" style="display:none;" id="download_name" value="'.$increm_row[rand_name].'"> </td>
				          <td ><button type="button" value="'.$increm_row[id].'" style="cursor:pointer; border:none; margin-top:25%; display:block; height:16px; width:16px; background:none; background-image:url(\'media/images/x.png\');" id="delete"></button></td>
						          </tr>';
		}
		
		$data = array('page' => $data1);
		
		break;
		
	case 'sub_category':
		
		$cat_id	=	$_REQUEST['cat_id'];
		$data 	= 	array('cat'=>Getcategory1($cat_id));
		
		break;	
	case 'set_task_type':
	
		$cat_id	=	$_REQUEST['cat_id'];
		$data 	= 	array('cat'=>Getbank_object($cat_id));
	
		break;
	case 'refresh':
		
		$data 	= 	array('date'=>date('d/m/y H:i'));
		
	break;
	
	case 'get_add_info':
	
		$pin	=	$_REQUEST['pin'];
		$data 	= 	array('info' => get_addition_all_info($pin));
	
		break;
		case 'get_add_info1':
		
		$personal_id	=	$_REQUEST['personal_id'];
		$data 	= 	array('info1' => get_addition_all_info1($personal_id));
	
		break;
	default:
		$error = 'Action is Null';
}

$data['error'] = $error;

echo json_encode($data);


/* ******************************
 *	Request Functions
* ******************************
*/
function checkgroup($user){
	$res = mysql_fetch_assoc(mysql_query("	SELECT users.group_id
											FROM    users
											WHERE  users.id = $user
											"));
	return $res['group_id'];

}
				
function Saveincomming($call_type_id, $phone, $category_id, $category_parent_id, $object_id, $pay_type_id, $bank_id, $card_type_id, $pay_aparat_id,  $problem_date, $call_content,$source_id,$file,$rand_file)
{
	
	global $error;
	$incom_id	= $_REQUEST['id'];
	$user		= $_SESSION['USERID'];
	$c_date		= date('Y-m-d H:i:s');
	$hidden_user	= $_REQUEST['hidden_user'];
	if ($hidden_user==$user) {
		mysql_query("UPDATE  `incomming_call`
					SET
								`user_id`				='$user',
								`date`					='$c_date',
								`phone`				='$phone',
								`call_type_id`			='$call_type_id',
								`call_category_id`		='$category_id',
								`call_subcategory_id`	='$category_parent_id',
								`object_id`			='$object_id',
								`pay_type_id`			='$pay_type_id',
								`bank_id`				='$bank_id',
								`card_type_id`			='$card_type_id',
								`pay_aparat_id`		='$pay_aparat_id',
								`problem_date`			='$problem_date',
								`call_content`			='$call_content',
								`source_id`				= '$source_id',
								`actived`				='1'
								WHERE     `id`					='$incom_id'
					");
					
	}else 
	{
		$error='თქვენ არ გაქვთ შეცვლის უფლება';
	}
	
}  

function note_incomming()
{
	global $error;
	$incom_id	= $_REQUEST['id'];
	$user		= $_SESSION['USERID'];
	$group		= checkgroup($user);
if ($group==2 || $group == 3) {
		mysql_query("UPDATE  `incomming_call`
						SET
							`noted`='1'
							WHERE   `id`='$incom_id'
			");
			
	}else
	{
		$error='ეს ფუნქცია თქვენთვის შეზღუდულია';
	}
}	
function Savetask($incom_id, $persons_id,  $task_type_id, $priority_id, $task_department_id, $comment)
{
	//GLOBAL $log;
	//$log->setUpdateLogAfter('task', $incom_id);

	$user  = $_SESSION['USERID'];
	
			mysql_query("UPDATE `task` SET  	 
										 `user_id`='$user',
									 	 `responsible_user_id`='$persons_id',
									 	 `task_type_id`='$task_type_id',
										 `priority_id`='$priority_id', 
										 `department_id`='$task_department_id', 
										 `comment`='$comment' 
										  WHERE (`incomming_call_id`='$incom_id');");
	//$log->setInsertLog('task',$incom_id);
}


function Getcall_status($status)
{
	$data = '';
	$req = mysql_query("SELECT 	`id`, `call_status`
						FROM 	`status`
						WHERE 	actived=1");
	

	$data .= '<option value="0" selected="selected">----</option>';
	while( $res = mysql_fetch_assoc($req)){
		
		if($res['id'] == $status){
			$data .= '<option value="' . $res['id'] . '" selected="selected">' . $res['call_status'] . '</option>';
		} else {
			$data .= '<option value="' . $res['id'] . '">' . $res['call_status'] . '</option>';
		}
	}
	return $data;
}
	function Getpay_type($pay_type_id)
	{
		$data = '';
		$req = mysql_query("SELECT 	`id`, `name`
						FROM 	`pay_type`
						WHERE 	actived=1");
	
	
		$data .= '<option value="0" selected="selected">----</option>';
		while( $res = mysql_fetch_assoc($req)){
			if($res['id'] == $pay_type_id){
				$data .= '<option value="' . $res['id'] . '" selected="selected">' . $res['name'] . '</option>';
			} else {
				$data .= '<option value="' . $res['id'] . '">' . $res['name'] . '</option>';
			}
		}
	
		return $data;
	}
	function Get_bank($bank_id)
	{
		$data = '';
		$req = mysql_query("SELECT 	`id`, `name`
						FROM 	`bank`
						WHERE 	actived=1");
	
	
		$data .= '<option value="0" selected="selected">----</option>';
		while( $res = mysql_fetch_assoc($req)){
			if($res['id'] == $bank_id){
				$data .= '<option value="' . $res['id'] . '" selected="selected">' . $res['name'] . '</option>';
			} else {
				$data .= '<option value="' . $res['id'] . '">' . $res['name'] . '</option>';
			}
		}
	
		return $data;
	}
	
function Getcard_type($card_type_id)
{
	$data = '';
	$req = mysql_query("SELECT 	`id`, `name`
					FROM 	`card_type`
					WHERE 	actived=1");


	$data .= '<option value="0" selected="selected">----</option>';
	while( $res = mysql_fetch_assoc($req)){
		if($res['id'] == $card_type_id){
			$data .= '<option value="' . $res['id'] . '" selected="selected">' . $res['name'] . '</option>';
		} else {
			$data .= '<option value="' . $res['id'] . '">' . $res['name'] . '</option>';
		}
	}

	return $data;
}
function Getpay_aparat($pay_aparat_id)
{
	$data = '';
	$req = mysql_query("SELECT 	`id`, `name`
					FROM 	`pay_aparat`
					WHERE 	actived=1");

	$data .= '<option value="0" selected="selected">----</option>';
	while( $res = mysql_fetch_assoc($req)){
		if($res['id'] == $pay_aparat_id){
			$data .= '<option value="' . $res['id'] . '" selected="selected">' . $res['name'] . '</option>';
		} else {
			$data .= '<option value="' . $res['id'] . '">' . $res['name'] . '</option>';
		}
	}

	return $data;
}
function Getobject($object_id)
{
	$data = '';
	$req = mysql_query("SELECT 	`id`, `name`
					FROM 	`object`
					WHERE 	actived=1");


	$data .= '<option value="0" selected="selected">----</option>';
	while( $res = mysql_fetch_assoc($req)){
		if($res['id'] == $object_id){
			$data .= '<option value="' . $res['id'] . '" selected="selected">' . $res['name'] . '</option>';
		} else {
			$data .= '<option value="' . $res['id'] . '">' . $res['name'] . '</option>';
		}
	}

	return $data;
}
function Getcategory($category_id)

{ 			

	$data = '';
	$req = mysql_query("SELECT `id`, `name`
						FROM `category`
						WHERE actived=1 && parent_id=0 ");


	$data .= '<option value="0" selected="selected">----</option>';
	while( $res = mysql_fetch_assoc($req)){
		if($res['id'] == $category_id){
			$data .= '<option value="' . $res['id'] . '" selected="selected">' . $res['name'] . '</option>';
		} else {
			$data .= '<option value="' . $res['id'] . '">' . $res['name'] . '</option>';
		}
	}

	return $data;
}

function Getcategory1($category_id)
{

	$data = '';
	$req = mysql_query("SELECT `id`, `name`
						FROM `category`
						WHERE actived=1 && parent_id=$category_id");

	$data .= '<option value="0" selected="selected">----</option>';
	while( $res = mysql_fetch_assoc($req)){
		if($res['id'] == $category_id){
			$data .= '<option value="' . $res['id'] . '" selected="selected">' . $res['name'] . '</option>';
		} else {
			$data .= '<option value="' . $res['id'] . '">' . $res['name'] . '</option>';
		}
	}

	return $data;
	
}

function Getcategory1_edit($category_id)
{

	$data = '';
	$req = mysql_query("SELECT `id`, `name`
						FROM `category`
						WHERE actived=1 && id=$category_id");

	$data .= '<option value="0" selected="selected">----</option>';
	while( $res = mysql_fetch_assoc($req)){
		if($res['id'] == $category_id){
			$data .= '<option value="' . $res['id'] . '" selected="selected">' . $res['name'] . '</option>';
		} else {
			$data .= '<option value="' . $res['id'] . '">' . $res['name'] . '</option>';
		}
	}

	return $data;

}

function Getcall_type($call_type_id)
{
	$data = '';
	$req = mysql_query("SELECT `id`, `name`
					FROM `call_type`
					WHERE actived=1");
	
	$data .= '<option value="0" selected="selected">----</option>';
	while( $res = mysql_fetch_assoc($req)){
		if($res['id'] == $call_type_id){
			$data .= '<option value="' . $res['id'] . '" selected="selected">' . $res['name'] . '</option>';
		} else {
			$data .= '<option value="' . $res['id'] . '">' . $res['name'] . '</option>';
		}
	}

	return $data;
}


function Getdepartment($task_department_id)
{
	$data = '';
	$req = mysql_query("SELECT `id`, `name`
					    FROM `department`
					    WHERE actived=1 ");
	

	$data .= '<option value="0" selected="selected">----</option>';
	while( $res = mysql_fetch_assoc($req)){
		if($res['id'] == $task_department_id){
			$data .= '<option value="' . $res['id'] . '" selected="selected">' . $res['name'] . '</option>';
		} else {
			$data .= '<option value="' . $res['id'] . '">' . $res['name'] . '</option>';
		}
	}

	return $data;
}
function Get_control($persons_id)
{
	$data = '';
	$req = mysql_query("SELECT `id`, `name`
						FROM `crystal_users`
						WHERE actived=1 ");

	$data .= '<option value="0" selected="selected">----</option>';
	while( $res = mysql_fetch_assoc($req)){
		if($res['id'] == $persons_id){
			$data .= '<option value="' . $res['id'] . '" selected="selected">' . $res['name'] . '</option>';
		} else {
			$data .= '<option value="' . $res['id'] . '">' . $res['name'] . '</option>';
		}
	}

	return $data;
}
function Getsource($object_id)
{
	$data = '';
	$req = mysql_query("SELECT 	`id`, `name`
					FROM 	`source`
					WHERE 	actived=1");


	$data .= '<option value="0" selected="selected">----</option>';
	while( $res = mysql_fetch_assoc($req)){
		if($res['id'] == $object_id){
			$data .= '<option value="' . $res['id'] . '" selected="selected">' . $res['name'] . '</option>';
		} else {
			$data .= '<option value="' . $res['id'] . '">' . $res['name'] . '</option>';
		}
	}

	return $data;
}

function Getpriority($priority_id)
{
	$data = '';
	$req = mysql_query("SELECT `id`, `name`
						FROM `priority`
						WHERE actived=1 ");

	$data .= '<option value="0" selected="selected">----</option>';
	while( $res = mysql_fetch_assoc($req)){
		if($res['id'] == $priority_id){
			$data .= '<option value="' . $res['id'] . '" selected="selected">' . $res['name'] . '</option>';
		} else {
			$data .= '<option value="' . $res['id'] . '">' . $res['name'] . '</option>';
		}
	}

	return $data;
}

function Gettask_type($task_type_id)
{
	$data = '';
	$req = mysql_query("SELECT `id`, `name`
					    FROM `task_type`
					    WHERE actived=1 ");

	$data .= '<option value="0" selected="selected">----</option>';
	while( $res = mysql_fetch_assoc($req)){
		if($res['id'] == $task_type_id){
			$data .= '<option value="' . $res['id'] . '" selected="selected">' . $res['name'] . '</option>';
		} else {
			$data .= '<option value="' . $res['id'] . '">' . $res['name'] . '</option>';
		}
	}

	return $data;
}


function Getpersons($persons_id)
{
	$data = '';
	$req = mysql_query("SELECT `id`, `name`
							FROM `crystal_users`
							WHERE actived=1");

	$data .= '<option value="0" selected="selected">----</option>';
	while( $res = mysql_fetch_assoc($req)){
		if($res['id'] == $persons_id){
			$data .= '<option value="' . $res['id'] . '" selected="selected">' . $res['name'] . '</option>';
		} else {
			$data .= '<option value="' . $res['id'] . '">' . $res['name'] . '</option>';
		}
	}

	return $data;
}

function getCalls(){
	

	$req = mysql_query("

						SELECT  	DISTINCT
									IF(SUBSTR(cdr.src, 1, 3) = 995, SUBSTR(cdr.src, 4, 9), cdr.src) AS `src`
						FROM    	cdr
						GROUP BY 	cdr.src
						ORDER BY 	cdr.calldate DESC
						LIMIT 		12


						");

	$data = '<tr class="trClass">
					<th class="thClass">#</th>
					<th class="thClass">ნომერი</th>
					<th class="thClass">ქმედება</th>
				</tr>
			';
	$i	= 1;
	while( $res3 = mysql_fetch_assoc($req)){

		$data .= '
	    		<tr class="trClass">
					<td class="tdClass">' . $i . '</td>
					<td class="tdClass" style="width: 30px !important;">' . $res3['src'] . '</td>
					<td class="tdClass" style="font-size: 13px !important;"><button class="insert" number="' . $res3['src'] . '">დამატება</button></td>
				</tr>';
		$i++;
	}

	return $data;


}

function get_addition_all_info($pin)
{
	$res1 = mysql_fetch_assoc(mysql_query("	SELECT COUNT(*) AS `a`
											FROM 			`incomming_call`
											LEFT JOIN 		task ON incomming_call.id = task.incomming_call_id
											WHERE 			incomming_call.pin = $pin AND incomming_call.call_type_id = 1 AND (task.`status` = 3 OR ISNULL(task.`status`))"));
	
	$res2 = mysql_fetch_assoc(mysql_query("	SELECT COUNT(*) AS `a1`
											FROM 			`incomming_call`
											LEFT JOIN 		task ON incomming_call.id = task.incomming_call_id
											WHERE 			incomming_call.pin = $pin AND incomming_call.call_type_id = 2 AND (task.`status` = 3 OR ISNULL(task.`status`))"));
	
	$res3 = mysql_fetch_assoc(mysql_query("	SELECT COUNT(*) AS `a2`
											FROM 			`incomming_call`
											LEFT JOIN 		task ON incomming_call.id = task.incomming_call_id
											WHERE 			incomming_call.pin = $pin AND incomming_call.call_type_id = 1 AND (task.`status` != 3 AND NOT ISNULL(task.`status`))"));
	
	$res4 = mysql_fetch_assoc(mysql_query("	SELECT COUNT(*) AS `a3`
											FROM 			`incomming_call`
											LEFT JOIN 		task ON incomming_call.id = task.incomming_call_id
											WHERE 			incomming_call.pin = $pin AND incomming_call.call_type_id = 2 AND (task.`status` != 3 AND NOT ISNULL(task.`status`))"));
	
	$sum_incomming	 	= $res1['a'] + $res2['a1'] + $res3['a2'] + $res4['a3'];
	$sum_end	 		= $res1['a'] + $res2['a1'];
	$sum_actived		= $res3['a2'] + $res4['a3'];
	
	$data .= '<fieldset>
					<legend>მომართვების ისტორია</legend>
					<table class="reqves_hist">
						<tr>
							<td>სულ</td>
							<td></td>
							<td></td>
							<td style="width: 150px;"></td>
							<td>'.$sum_incomming.'</td>
						</tr>
						<tr>
							<td></td>
							<td>მოგვარებულები</td>
							<td></td>
							<td style="width: 150px;"></td>
						    <td>'.$sum_end.'</td>
						</tr>
						<tr>
							<td></td>
							<td></td>
							<td>პრობლემა</td>
							<td style="width: 150px;"></td>
							<td>'. $res1['a'].'</td>
						</tr>
						<tr>
							<td></td>
							<td></td>
							<td>ინფორმაცია</td>
							<td style="width: 150px;"></td>
							<td>'.$res2['a1'].'</td>
						</tr>
						<tr>
							<td></td>
							<td>მოუგვარებელი</td>
							<td></td>
							<td style="width: 150px;"></td>
							<td>'.$sum_actived.'</td>
						</tr>
						<tr>
							<td></td>
							<td></td>
							<td>პრობლემა</td>
							<td style="width: 150px;"></td>
							<td>'.$res3['a2'].'</td>
						</tr>
						<tr>
							<td></td>
							<td></td>
							<td>ინფორმაცია</td>
							<td style="width: 150px;"></td>
							<td>'. $res4['a3'].'</td>
						</tr>
					</table>
				</fieldset>';

	return $data;
}
function get_addition_all_info1($personal_id)
{
	$res1 = mysql_fetch_assoc(mysql_query("	SELECT COUNT(*) AS `a`
											FROM 			`incomming_call`
											LEFT JOIN 		task ON incomming_call.id = task.incomming_call_id
											WHERE 			incomming_call.pid = $personal_id AND incomming_call.call_type_id = 1 AND (task.`status` = 3 OR ISNULL(task.`status`))"));

	$res2 = mysql_fetch_assoc(mysql_query("	SELECT COUNT(*) AS `a1`
											FROM 			`incomming_call`
											LEFT JOIN 		task ON incomming_call.id = task.incomming_call_id
											WHERE 			incomming_call.pid = $personal_id AND incomming_call.call_type_id = 2 AND (task.`status` = 3 OR ISNULL(task.`status`))"));

	$res3 = mysql_fetch_assoc(mysql_query("	SELECT COUNT(*) AS `a2`
											FROM 			`incomming_call`
											LEFT JOIN 		task ON incomming_call.id = task.incomming_call_id
											WHERE 			incomming_call.pid = $personal_id AND incomming_call.call_type_id = 1 AND (task.`status` != 3 AND NOT ISNULL(task.`status`))"));

	$res4 = mysql_fetch_assoc(mysql_query("	SELECT COUNT(*) AS `a3`
											FROM 			`incomming_call`
											LEFT JOIN 		task ON incomming_call.id = task.incomming_call_id
											WHERE 			incomming_call.pid = $personal_id AND incomming_call.call_type_id = 2 AND (task.`status` != 3 AND NOT ISNULL(task.`status`))"));

	$sum_incomming	 	= $res1['a'] + $res2['a1'] + $res3['a2'] + $res4['a3'];
	$sum_end	 		= $res1['a'] + $res2['a1'];
	$sum_actived		= $res3['a2'] + $res4['a3'];

	$data .= '<fieldset>
					<legend>მომართვების ისტორია</legend>
					<table class="reqves_hist">
						<tr>
							<td>სულ</td>
							<td></td>
							<td></td>
							<td style="width: 150px;"></td>
							<td>'.$sum_incomming.'</td>
						</tr>
						<tr>
							<td></td>
							<td>მოგვარებულები</td>
							<td></td>
							<td style="width: 150px;"></td>
						    <td>'.$sum_end.'</td>
						</tr>
						<tr>
							<td></td>
							<td></td>
							<td>პრობლემა</td>
							<td style="width: 150px;"></td>
							<td>'. $res1['a'].'</td>
						</tr>
						<tr>
							<td></td>
							<td></td>
							<td>ინფორმაცია</td>
							<td style="width: 150px;"></td>
							<td>'.$res2['a1'].'</td>
						</tr>
						<tr>
							<td></td>
							<td>მოუგვარებელი</td>
							<td></td>
							<td style="width: 150px;"></td>
							<td>'.$sum_actived.'</td>
						</tr>
						<tr>
							<td></td>
							<td></td>
							<td>პრობლემა</td>
							<td style="width: 150px;"></td>
							<td>'.$res3['a2'].'</td>
						</tr>
						<tr>
							<td></td>
							<td></td>
							<td>ინფორმაცია</td>
							<td style="width: 150px;"></td>
							<td>'. $res4['a3'].'</td>
						</tr>
						<tr>
							<td></td>
							<td></td>
							<td></td>
							<td style="width: 150px;"></td>
				    		<td style="width: 300px;">
							<input type="button" value="ვრცლად"/>
		      				</td>
						</tr>
					</table>
				</fieldset>';

	return $data;
}
function Getincomming($incom_id)
{
	
	if (substr($incom_id,0,1)=='a')
	{
		$incom_id=substr($incom_id,1,4);
			$res = mysql_fetch_assoc(mysql_query("SELECT 	task.id AS `id`,
															incomming_call.id AS `call_id`,
															incomming_call.uniqueid as inc_uniqueid,
															task.uniqueid as task_uniqueid,
															crystal_users.`name` AS operator,
															IF(ISNULL(task.incomming_call_id), task.phone, incomming_call.phone) AS phone,
															IF(ISNULL(task.incomming_call_id), DATE_FORMAT(task.`date`,'%d/%m/%y %H:%i'), DATE_FORMAT(incomming_call.`date`,'%d/%m/%y %H:%i:%s')) AS call_date,
															IF(ISNULL(task.incomming_call_id), DATE_FORMAT(task.`date`,'%Y-%m-%d %H'),DATE_FORMAT(incomming_call.`date`,'%Y-%m-%d')) AS record_date,
															incomming_call.call_type_id AS call_type_id,
															incomming_call.call_category_id AS category_id,
															IF(ISNULL(task.`status`), 3, task.`status`) AS `status`,
															incomming_call.call_subcategory_id AS category_parent_id,
															DATE_FORMAT(incomming_call.`problem_date`,'%d/%m/%y %H:%i') AS problem_date,
															incomming_call.call_content AS call_content,
															incomming_call.pay_type_id AS pay_type_id,
															incomming_call.bank_id AS bank_id,
															incomming_call.bank_object_id AS bank_object_id,
															incomming_call.card_type_id AS card_type_id,
															incomming_call.card_type_id AS card_type1_id,
															incomming_call.pay_aparat_id AS pay_aparat_id,
															incomming_call.object_id AS object_id,
															incomming_call.pid AS personal_id,
															incomming_call.pin AS personal_pin,
															incomming_call.money,
															task.task_type_id AS task_type_id,
															task.responsible_user_id AS persons_id,
															task.priority_id AS priority_id,
															DATE_FORMAT(task.`planned_end_date`,'%d/%m/%y %H:%i:%s') as planned_end_date,
															DATE_FORMAT(task.fact_end_date,'%d/%m/%y %H:%i:%s') as fact_end_date,
															CONCAT(DATEDIFF(task.`fact_end_date`, task.`date`),' ','დღე და',' ',TIMEDIFF(DATE_FORMAT(task.`fact_end_date`,'%H:%i:%s'),DATE_FORMAT(task.`date`,'%H:%i:%s')),' ', 'სთ') as duration,
															task.department_id AS task_department_id,
															task.phone AS task_phone,
															task.`comment` AS `comment`,
															task.control_user_id,
															task.problem_comment AS problem_comment
													

										FROM 	   	task
										LEFT JOIN  	incomming_call  ON incomming_call.id = task.incomming_call_id
										LEFT JOIN   crystal_users ON incomming_call.user_id=crystal_users.id
										WHERE      	task.id =$incom_id
				" ));
	}
	else{
$res = mysql_fetch_assoc(mysql_query("SELECT    	incomming_call.id AS id,
													incomming_call.phone AS `phone`,
													incomming_call.uniqueid as inc_uniqueid,
													task.uniqueid as task_uniqueid,
													crystal_users.`name` AS operator,
													incomming_call.user_id AS `user_id`,
													DATE_FORMAT(incomming_call.`date`,'%d/%m/%y %H:%i') AS call_date,
													DATE_FORMAT(incomming_call.`date`,'%Y-%m-%d %H') AS record_date,
													incomming_call.call_type_id AS call_type_id,
													incomming_call.call_category_id AS category_id,
													IF(ISNULL(task.`status`), 3, task.`status`) AS `status`,
													incomming_call.call_subcategory_id AS category_parent_id,
													DATE_FORMAT(incomming_call.`problem_date`,'%d/%m/%y %H:%i') AS problem_date,
													incomming_call.call_content AS call_content,
													incomming_call.pay_type_id AS pay_type_id,
													incomming_call.bank_id AS bank_id,
													incomming_call.bank_object_id AS bank_object_id,
													incomming_call.card_type_id AS card_type_id,
													incomming_call.card_type_id AS card_type1_id,
													incomming_call.pay_aparat_id AS pay_aparat_id,
													incomming_call.object_id AS object_id,
													incomming_call.source_id,
													incomming_call.pin AS personal_pin,
													incomming_call.pid AS personal_id,
													incomming_call.money,
													task.task_type_id AS task_type_id,
													task.responsible_user_id AS persons_id,
													task.priority_id AS priority_id,
													task.control_user_id,
													task.problem_comment,
													task.phone as task_phone,
													task.department_id AS task_department_id
										FROM 	 incomming_call
										LEFT JOIN  	task  ON incomming_call.id=task.incomming_call_id
										LEFT JOIN crystal_users ON crystal_users.id=incomming_call.user_id
										
										where      	incomming_call.id =$incom_id
			" ));
	}
	
	return $res;
}


function GetPage($res='', $number)
{
	$num = 0;
	if($res[phone]==""){
		$num=$number;
	}else{ 
		$num=$res[phone]; 
	}

	$increm = mysql_query("	SELECT  `name`,
									`rand_name`
							FROM 	`file`
							WHERE   `incomming_call_id` = $res[id]
			");
	
	$data  .= '
	<!-- jQuery Dialog -->
    <div id="add-edit-goods-form" title="საქონელი">
    	<!-- aJax -->
	</div>
	<div id="dialog-form">
			<div style="float: left; width: 673px;">	
				<fieldset >
			    	<legend>ძირითადი ინფორმაცია</legend>
					<tr>
						<label for="req_num">დამფორმირებელი</label>
						<label for="req_num">:</label>
						<label for="req_num">' .  $res['operator']. '</label>
					</tr>
			    	<table width="100%" class="dialog-form-table">
						<tr>
							<td style="width: 180px;"><label for="req_num">მომართვა №</label></td>
							<td style="width: 180px !important;"><label for="req_data">თარიღი</label></td>
							<td style="width: 180px;"><label for="req_phone">ტელეფონი</label></td>
						</tr>
						<tr>
							<td style="width: 180px;">
								<input type="text" id="id" class="idle" onblur="this.className=\'idle\'" onfocus="this.className=\'activeField user_id\'" value="' . $res['id']. '" disabled="disabled" />
							</td>
							<td style="width: 180px;">
								<input type="text" id="c_date" class="idle" onblur="this.className=\'idle\'" onfocus="this.className=\'activeField date\'" value="' .  $res['call_date']. '" disabled="disabled" />
							</td>
							<td style="width: 180px;">
								<input type="text" id="phone" class="idle" onblur="this.className=\'idle\'" onfocus="this.className=\'activeField\'" value="' . $num . '" />
							</td>
							<td style="width: 69px;">
								<button id="button_calls" class="calls">ნომრები</button>
							</td>
						</tr>
						<tr>
							<td style="width: 180px;"><label for="d_number">ზარის ტიპი</label></td>
							<td style="width: 180px;"><label for="d_number">კატეგორია</label></td>
							<td style="width: 180px;"><label for="d_number">ქვე-კატეგოტია</label></td>
							<td ></td>
						</tr>
						<tr>
							<td style="width: 180px;"><select id="call_type_id" class="idls object">'. Getcall_type($res['call_type_id']).'</select></td>
							<td style="width: 180px;"><select id="category_parent_id" class="idls object">'. Getcategory($res['category_parent_id']).'</select></td>
							<td style="width: 180px;"><select id="category_id" class="idls object">'. Getcategory1_edit($res['category_id']).'</select></td>
							<td ></td>
						</tr>
					</table>';
										
		$data  .= '<table id="additional" class="hidden dialog-form-table" width="100%">

						<tr id="aaaa">
							<td style="width: 180px;"><label pey_label1 for="d_number">ტრანზაქციის ფორმა</label></td>
							<td style="width: 180px;"><label id="bank_label" for="d_number">მომსახურე ბანკი</label></td>
							<td style="width: 180px;"><label id="pey_label" for="d_number">აპარატის ტიპი</label></td>
							<td style="width: 106px;"></td>
						</tr>
						<tr id="c">
							<td style="width: 180px;"><select id="pay_type_id" class="idls object">'. Getpay_type($res['pay_type_id']).'</select></td>
							<td style="width: 180px;"><select id="bank_id" class="idls object">'. Get_bank($res['bank_id']).'</select></td>
							<td style="width: 180px;"><select id="pay_aparat_id" class="idls object">'. Getpay_aparat($res['pay_aparat_id']).'</select></td>
							<td style="width: 106px;"></td>
						</tr>
						<tr id="bbbb">
							<td style="width: 180px;"><label id="card_label" for="d_number">ბარათის ტიპი</label></td>
							<td style="width: 180px;"><label for="d_number">თანხის რაოდენობა</label></td>
							<td style="width: 180px;"></td>
							<td style="width: 106px;"></td>
						</tr>
						<tr id="d" >
							<td style="width: 180px;"><select id="card_type_id" class="idls object">'. Getcard_type($res['card_type_id']).'</select></td>
							<td style="width: 180px;">
								<input type="text" id="money" class="idle" onblur="this.className=\'idle\'" onfocus="this.className=\'activeField\'" value="' . $res['money'] . '" />
							</td>
							<td style="width: 180px;"></td>
							<td style="width: 106px;"></td>
						</tr>
					</table>';
												
		$data  .= '<table width="100%" class="dialog-form-table">
						<tr>
							<td style="width: 180px;"><label for="req_num">პრობლემის თარიღი</label></td>
							<td style="width: 180px;"><label for="d_number">სტატუსი</label></td>
							<td style="width: 180px;"><label for="d_number">ობიექტი</label></td>			
							<td ></td>
						</tr>
						<tr>	
							<td style="width: 180px;"><input type="text" id="problem_date" class="idle" onblur="this.className=\'idle\'" onfocus="this.className=\'activeField\'" value="' . $res[problem_date] . '" /></td>
							<td style="width: 180px;"><select id="call_status_id" class="idls object"disabled="disabled">'. Getcall_status($res['status']).'</select></td>
							<td style="width: 180px;"><select id="object_id" class="idls object">'. Getobject($res['object_id']).'</select></td>	
							<td ></td>
						</tr>
						<tr>
							<td style="width: 180px;"><label for="req_num">ინფორმაციის წყარო</label></td>
							<td style="width: 180px;"><label for="d_number">თანხის რაოდენობა</label></td>
							<td style="width: 180px;"></td>			
							<td ></td>
						</tr>
						<tr>	
							<td style="width: 180px;"><select id="source_id" class="idls object">'. Getsource($res['source_id']).'</select></td>
							<td style="width: 180px;">
								<input type="text" id="money" class="idle" onblur="this.className=\'idle\'" onfocus="this.className=\'activeField\'" value="' . $res['card_type_id'] . '" />
							</td>
							<td style="width: 180px;"></td>	
							<td ></td>
						</tr>
						<tr>
							<td style="width: 180px;"><label for="content">საუბრის შინაარსი</label></td>
						</tr>
						<tr>
							
							<td colspan="6">	
								<textarea  style="width: 641px; resize: none;" id="call_content" class="idle" name="call_content" cols="300" rows="4">' . $res['call_content'] . '</textarea>
							</td>
						</tr>			
					</table>
				</fieldset >
		   
				<fieldset style="margin-top: 5px;">
			    	<legend>დავალების ფორმირება</legend>
		
			    	<table class="dialog-form-table">
						<tr>
							<td style="width: 180px;"><label for="d_number">დავალების ტიპი</label></td>
							<td style="width: 180px;"><label for="d_number">განყოფილება</label></td>
							<td style="width: 180px;"><label for="d_number">პასუხისმგებელი პირი</label></td>
						</tr>
			    		<tr>
							<td style="width: 180px;" id="task_type_change"><select id="task_type_id" class="idls object">'.Gettask_type($res['task_type_id']).'</select></td>
							<td style="width: 180px;"><select id="task_department_id" class="idls object">'. Getdepartment($res['task_department_id']).'</select></td>
							<td style="width: 180px;"><select id="persons_id" class="idls object">'.Getpersons($res['persons_id']).'</select></td>
						</tr>
						<tr>
							<td style="width: 180px;"><label for="d_number">პრიორიტეტები</label></td>
							<td style="width: 180px;"><label for="d_number">მაკონტროლებელი</label></td>
							<td style="width: 180px;"><label for="d_number">სხვა ნომერი</label></td>
						</tr>
						<tr>
							<td style="width: 180px;"><select id="priority_id" class="idls object">'.Getpriority($res['priority_id']).'</select></td>
							<td style="width: 180px;"><select id="controler_id" class="idls object">'.Get_control($res['control_user_id']).'</select></td>
							<td style="width: 180px;"><input type="text" id="task_phone" class="idle" onblur="this.className=\'idle\'" value="' . $res[task_phone] . '" /></td>
						</tr>
						<tr>
							<td style="width: 180px;"><label for="content">პრობლემის გადაწყვეტა</label></td>
						</tr>
						<tr>
							
							<td colspan="6">	
								<textarea  style="width: 641px; resize: none;" id="problem_coment" class="idle" name="call_content" cols="300" rows="4"disabled="disabled">' . $res['problem_comment'] . '</textarea>
							</td>
						</tr>	
					</table>
		        </fieldset>
			</div>
			<div>
				  </fieldset>
			</div>
			<div style="float: right;  width: 355px;">
				<fieldset>
					<legend>მომართვის ავტორი</legend>
					<table style="height: 172px;">
						<tr>
							<td style="width: 180px;">PIN კოდი</td>
							<td style="width: 180px;"></td>
						</tr>
						<tr>
							<td style="width: 180px;"><input type="text" id="personal_pin" class="idle" onblur="this.className=\'idle\'" onfocus="this.className=\'activeField\'" value="' . $res['personal_pin']  . '"disabled="disabled" /></td>
							<td style="width: 180px;" class="hidden friend">
							<input type="text" id="friend_pin" class="idle" onblur="this.className=\'idle\'" onfocus="this.className=\'activeField\'" value="' . $res['friend_pin'] . '" disabled="disabled"/>
							</td>
						</tr>
						<tr>
							<td style="width: 180px;">პირადი ნომერი</td>
							<td style="width: 180px;"></td>
						</tr>
						<tr>
							<td style="width: 180px;">
								<input type="text" id="personal_id" class="idle" onblur="this.className=\'idle\'" onfocus="this.className=\'activeField\'" value="' . $res['personal_id'] . '"disabled="disabled" />
							</td>
							<td style="width: 180px;"></td>
						</tr>
						<td style="width: 69px;">
							<button id="search" class="calls">ძიება</button>
						</td>
					</table>
				</fieldset>
				<div id="additional_info">';
					if (!empty($res['personal_pin'])){
							$data .= get_addition_all_info($res['personal_pin']);
						}
	  $data .= '</div>';
	  
	  		$data .= GetRecordingsSection1($res);
	  		$data .= GetRecordingsSection($res);
	  		
		$data .= '		<fieldset>
					<legend>დამატებითი ინფორმაცია</legend> 
					<table style="float: right; border: 1px solid #85b1de; width: 150px; text-align: center;">
					<tr>
						<td>
							<div class="file-uploader">
								<input id="choose_file" type="file" name="choose_file" class="input" style="display: none;">
								<button id="choose_button" class="center">აირჩიეთ ფაილი</button>
								<input id="hidden_inc" type="text" value="'. increment('incomming_call') .'" style="display: none;">
							</div>
						</td>
					</tr>
				</table>
			     <table style="float: right; border: 1px solid #85b1de; width: 150px; text-align: center;">
			          <tr style="border-bottom: 1px solid #85b1de;">
			           <td colspan="3">მიმაგრებული ფაილი</td>
			          </tr>
				</table>
				<table id="file_div" style="float: right; border: 1px solid #85b1de; width: 150px; text-align: center;">';
					
					while($increm_row = mysql_fetch_assoc($increm))	{	
						$data .=' 
								        <tr style="border-bottom: 1px solid #85b1de;">
								          <td style="width:110px; display:block;word-wrap:break-word;">'.$increm_row[name].'</td>													 
								          <td ><button type="button" value="media/uploads/file/'.$increm_row[rand_name].'" style="cursor:pointer; border:none; margin-top:25%; display:block; height:16px; width:16px; background:none;background-image:url(\'media/images/get.png\');" id="download" ></button><input type="text" style="display:none;" id="download_name" value="'.$increm_row[rand_name].'"> </td>
								          <td ><button type="button" value="'.$increm_row[id].'" style="cursor:pointer; border:none; margin-top:25%; display:block; height:16px; width:16px; background:none; background-image:url(\'media/images/x.png\');" id="delete"></button></td>
								        </tr>';
					}
			         
	 $data .= '
	 		</table>
				</fieldset>
			</div>
	 		<input id="hidden_user" type="text" value="'. $res['user_id'] .'" style="display: none;">
    </div>';

	return $data;
}

function GetRecordingsSection($res)
{
	if ($res[phone]==''){
		
	}else{
	$req = mysql_query("SELECT  	DATE_FORMAT(asterisk_incomming.call_datetime,'%d/%m/%y %H:%i:%s') AS `time`,
									asterisk_incomming.file_name AS `userfield`
						FROM 		asterisk_incomming
						WHERE		asterisk_incomming.uniqueid ='$res[inc_uniqueid]'");
	}
	$data .= '
        <fieldset style="margin-top: 0px; width: 155px; float: right;">
            <legend>შემომავალი ზარი</legend>

            <table style="width: 65%; border: solid 1px #85b1de; margin:auto;">
                <tr style="border-bottom: solid 1px #85b1de; height: 20px;">
                    <th style="padding-left: 10px;">დრო</th>
                    <th  style="border: solid 1px #85b1de; padding-left: 10px;">ჩანაწერი</th>
                </tr>';
	if (mysql_num_rows($req) == 0){
		$data .= '<td colspan="2" style="height: 20px; text-align: center;">ჩანაწერები ვერ მოიძებნა</td>';
	}
	
	while( $res2 = mysql_fetch_assoc($req)){
		$src = $res2['userfield'];
		$data .= '
                <tr style="border-bottom: solid 1px #85b1de; height: 20px;">
                    <td>' . $res2['time'] . '</td>
                    <td><button class="download" str="' . $src . '">შემომავალი</button></td>
                </tr>';
	}

	$data .= '
            </table>
        </fieldset>';
	
	return $data;
}
function GetRecordingsSection1($res)
{
	if ($res[phone]==''){
		
	}else{
		$req = mysql_query("SELECT  DATE_FORMAT(asterisk_outgoing.call_datetime,'%d/%m/%y %H:%i:%s') AS `time`,
									asterisk_outgoing.file_name AS `userfield`
							FROM 	asterisk_outgoing
							WHERE 	asterisk_outgoing.uniqueid='$res[task_uniqueid]'");
	}
	$data .= '
        <fieldset style="margin-top: 0px; width: 154px; float: right;">
            <legend>გამავალი ზარი</legend>

            <table style="width: 65%; border: solid 1px #85b1de; margin:auto;">
                <tr style="border-bottom: solid 1px #85b1de; height: 20px;">
                    <th style="padding-left: 10px;">დრო</th>
                    <th  style="border: solid 1px #85b1de; padding-left: 10px;">ჩანაწერი</th>
                </tr>';
	if (mysql_num_rows($req) == 0){
		$data .= '<td colspan="2" style="height: 20px; text-align: center;">ჩანაწერები ვერ მოიძებნა</td>';
	}

	while( $res2 = mysql_fetch_assoc($req)){
		$src = $res2['userfield'];
		$data .= '
                <tr style="border-bottom: solid 1px #85b1de; height: 20px;">
                    <td>' . $res2['time'] . '</td>
                    <td><button class="download1" str="' . $src . '">გამავალი</button></td>
                </tr>';
	}

	$data .= '
            </table>
        </fieldset>';

	return $data;
}
function increment($table){

	$result   		= mysql_query("SHOW TABLE STATUS LIKE '$table'");
	$row   			= mysql_fetch_array($result);
	$increment   	= $row['Auto_increment'];
	$next_increment = $increment+1;
	mysql_query("ALTER TABLE '$table' AUTO_INCREMENT=$next_increment");

	return $increment;
}

?>
